/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.shared.model;

import java.io.File;

import javax.xml.bind.annotation.XmlType;

import com.google.common.annotations.GwtCompatible;
import com.google.gson.annotations.Expose;
import com.sun.javadoc.SourcePosition;

/**
 * Implementation of {@link SourcePosition}
 *
 * @author Chad Retz
 */
@XmlType(name = "sourcePosition")
@GwtCompatible(serializable = true)
@SuppressWarnings("serial")
public class SourcePositionImpl extends JavadocNgEntity implements SourcePosition {

    //exposed fields
    
    @Expose
    private int column;
    
    @Expose
    private String file;
    
    @Expose
    private int line;
    
    //non-exposed fields
    
    private transient File fileLoaded;
    
    //constructors
    
    public SourcePositionImpl() {
        
    }
    
    public SourcePositionImpl(int line, int column, String file) {
        this.line = line;
        this.column = column;
        this.file = file;
    }
    
    //SourcePosition interface impl
    
    @Override
    public int column() {
        return column;
    }
    
    @Override
    public File file() {
        if (fileLoaded == null) {
            fileLoaded = new File(file);
        }
        return fileLoaded;
    }
    
    @Override
    public int line() {
        return line;
    }
    
    @Override
    public String toString() {
        return file + ":" + line;
    }
    
    //other accessors
    
    public void setColumn(int column) {
        this.column = column;
    }
    
    public String getFile() {
        return file;
    }
    
    public void setFile(String file) {
        this.file = file;
    }
    
    public void setLine(int line) {
        this.line = line;
    }
}
